<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - coverage.lcov - src/messages/mqtt_client_mqtt_variable_header.dart</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">src/messages</a> - mqtt_client_mqtt_variable_header.dart<span style="font-size: 80%;"> (source / <a href="mqtt_client_mqtt_variable_header.dart.func.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">coverage.lcov</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">49</td>
            <td class="headerCovTableEntry">49</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2017-10-09</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntryHi">-</td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /*</a>
<span class="lineNum">       2 </span>            :  * Package : mqtt_client
<span class="lineNum">       3 </span>            :  * Author : S. Hamblett &lt;steve.hamblett@linux.com&gt;
<span class="lineNum">       4 </span>            :  * Date   : 31/05/2017
<span class="lineNum">       5 </span>            :  * Copyright :  S.Hamblett
<span class="lineNum">       6 </span>            :  */
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : part of mqtt_client;
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : /// Enumeration used by subclasses to tell the variable header what should be read from the underlying stream.
<span class="lineNum">      11 </span>            : enum readWriteFlags {
<span class="lineNum">      12 </span>            :   none,
<span class="lineNum">      13 </span>            :   protocolName,
<span class="lineNum">      14 </span>            :   protocolVersion,
<span class="lineNum">      15 </span>            :   connectFlags,
<span class="lineNum">      16 </span>            :   keepAlive,
<span class="lineNum">      17 </span>            :   returnCode,
<span class="lineNum">      18 </span>            :   topicName,
<span class="lineNum">      19 </span>            :   messageIdentifier
<span class="lineNum">      20 </span>            : }
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            : /// Represents the base class for the Variable Header portion of some MQTT Messages.
<span class="lineNum">      23 </span>            : class MqttVariableHeader {
<span class="lineNum">      24 </span>            :   /// The length, in bytes, consumed by the variable header.
<span class="lineNum">      25 </span>            :   int length = 0;
<span class="lineNum">      26 </span>            : 
<span class="lineNum">      27 </span>            :   String protocolName = &quot;&quot;;
<span class="lineNum">      28 </span>            :   int protocolVersion = 0;
<span class="lineNum">      29 </span>            :   MqttConnectFlags connectFlags;
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            :   /// Defines the maximum allowable lag, in seconds, between expected messages.
<span class="lineNum">      32 </span>            :   /// The spec indicates that clients won't be disconnected until KeepAlive + 1/2 KeepAlive time period
<span class="lineNum">      33 </span>            :   /// elapses.
<span class="lineNum">      34 </span>            :   int keepAlive = 0;
<span class="lineNum">      35 </span>            : 
<span class="lineNum">      36 </span>            :   MqttConnectReturnCode returnCode = MqttConnectReturnCode.brokerUnavailable;
<span class="lineNum">      37 </span>            :   String topicName = &quot;&quot;;
<span class="lineNum">      38 </span>            :   int messageIdentifier = 0;
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            :   /// Initializes a new instance of the MqttVariableHeader class.
<span class="lineNum">      41 </span><span class="lineCov">          6 :   MqttVariableHeader() {</span>
<span class="lineNum">      42 </span><span class="lineCov">         12 :     this.protocolName = Protocol.name;</span>
<span class="lineNum">      43 </span><span class="lineCov">         12 :     this.protocolVersion = Protocol.version;</span>
<span class="lineNum">      44 </span><span class="lineCov">         12 :     this.connectFlags = new MqttConnectFlags();</span>
<span class="lineNum">      45 </span>            :   }
<span class="lineNum">      46 </span>            : 
<span class="lineNum">      47 </span>            :   /// Initializes a new instance of the MqttVariableHeader class, populating it with data from a stream.
<span class="lineNum">      48 </span><span class="lineCov">          4 :   MqttVariableHeader.fromByteBuffer(MqttByteBuffer headerStream) {</span>
<span class="lineNum">      49 </span><span class="lineCov">          4 :     readFrom(headerStream);</span>
<span class="lineNum">      50 </span>            :   }
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            :   /// Creates a variable header from the specified header stream.
<span class="lineNum">      53 </span>            :   /// A subclass can override this method to do completely custom read operations
<span class="lineNum">      54 </span>            :   /// if required.
<span class="lineNum">      55 </span>            :   void readFrom(MqttByteBuffer variableHeaderStream) {
<span class="lineNum">      56 </span><span class="lineCov">          1 :     readProtocolName(variableHeaderStream);</span>
<span class="lineNum">      57 </span><span class="lineCov">          1 :     readProtocolVersion(variableHeaderStream);</span>
<span class="lineNum">      58 </span><span class="lineCov">          1 :     readConnectFlags(variableHeaderStream);</span>
<span class="lineNum">      59 </span><span class="lineCov">          1 :     readKeepAlive(variableHeaderStream);</span>
<span class="lineNum">      60 </span><span class="lineCov">          1 :     readReturnCode(variableHeaderStream);</span>
<span class="lineNum">      61 </span><span class="lineCov">          1 :     readTopicName(variableHeaderStream);</span>
<span class="lineNum">      62 </span><span class="lineCov">          1 :     readMessageIdentifier(variableHeaderStream);</span>
<span class="lineNum">      63 </span>            :   }
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span>            :   /// Writes the variable header to the supplied stream.
<span class="lineNum">      66 </span>            :   /// A subclass can override this method to do completely custom write operations
<span class="lineNum">      67 </span>            :   /// if required.
<span class="lineNum">      68 </span>            :   void writeTo(MqttByteBuffer variableHeaderStream) {
<span class="lineNum">      69 </span><span class="lineCov">          1 :     writeProtocolName(variableHeaderStream);</span>
<span class="lineNum">      70 </span><span class="lineCov">          1 :     writeProtocolVersion(variableHeaderStream);</span>
<span class="lineNum">      71 </span><span class="lineCov">          1 :     writeConnectFlags(variableHeaderStream);</span>
<span class="lineNum">      72 </span><span class="lineCov">          1 :     writeKeepAlive(variableHeaderStream);</span>
<span class="lineNum">      73 </span><span class="lineCov">          1 :     writeReturnCode(variableHeaderStream);</span>
<span class="lineNum">      74 </span><span class="lineCov">          1 :     writeTopicName(variableHeaderStream);</span>
<span class="lineNum">      75 </span><span class="lineCov">          1 :     writeMessageIdentifier(variableHeaderStream);</span>
<span class="lineNum">      76 </span>            :   }
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            :   /// Gets the length of the write data when WriteTo will be called.
<span class="lineNum">      79 </span>            :   /// A subclass that overrides writeTo must also overwrite this method.
<span class="lineNum">      80 </span>            :   int getWriteLength() {
<span class="lineNum">      81 </span>            :     int headerLength = 0;
<span class="lineNum">      82 </span><span class="lineCov">          1 :     final MqttEncoding enc = new MqttEncoding();</span>
<span class="lineNum">      83 </span><span class="lineCov">          3 :     headerLength += enc.getByteCount(protocolName);</span>
<span class="lineNum">      84 </span><span class="lineCov">          1 :     headerLength += 1; // protocolVersion</span>
<span class="lineNum">      85 </span><span class="lineCov">          2 :     headerLength += MqttConnectFlags.getWriteLength();</span>
<span class="lineNum">      86 </span><span class="lineCov">          1 :     headerLength += 2; // keepAlive</span>
<span class="lineNum">      87 </span><span class="lineCov">          1 :     headerLength += 1; // returnCode</span>
<span class="lineNum">      88 </span><span class="lineCov">          4 :     headerLength += enc.getByteCount(topicName.toString());</span>
<span class="lineNum">      89 </span><span class="lineCov">          1 :     headerLength += 2; // MessageIdentifier</span>
<span class="lineNum">      90 </span>            :     return headerLength;
<span class="lineNum">      91 </span>            :   }
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            :   /// Write functions
<span class="lineNum">      94 </span>            : 
<span class="lineNum">      95 </span>            :   void writeProtocolName(MqttByteBuffer stream) {
<span class="lineNum">      96 </span><span class="lineCov">          8 :     MqttByteBuffer.writeMqttString(stream, protocolName);</span>
<span class="lineNum">      97 </span>            :   }
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span>            :   void writeProtocolVersion(MqttByteBuffer stream) {
<span class="lineNum">     100 </span><span class="lineCov">          8 :     stream.writeByte(protocolVersion);</span>
<span class="lineNum">     101 </span>            :   }
<span class="lineNum">     102 </span>            : 
<span class="lineNum">     103 </span>            :   void writeKeepAlive(MqttByteBuffer stream) {
<span class="lineNum">     104 </span><span class="lineCov">          8 :     stream.writeShort(keepAlive);</span>
<span class="lineNum">     105 </span>            :   }
<span class="lineNum">     106 </span>            : 
<span class="lineNum">     107 </span>            :   void writeReturnCode(MqttByteBuffer stream) {
<span class="lineNum">     108 </span><span class="lineCov">         12 :     stream.writeByte(returnCode.index);</span>
<span class="lineNum">     109 </span>            :   }
<span class="lineNum">     110 </span>            : 
<span class="lineNum">     111 </span>            :   void writeTopicName(MqttByteBuffer stream) {
<span class="lineNum">     112 </span><span class="lineCov">          6 :     MqttByteBuffer.writeMqttString(stream, topicName.toString());</span>
<span class="lineNum">     113 </span>            :   }
<span class="lineNum">     114 </span>            : 
<span class="lineNum">     115 </span>            :   void writeMessageIdentifier(MqttByteBuffer stream) {
<span class="lineNum">     116 </span><span class="lineCov">          4 :     stream.writeShort(messageIdentifier);</span>
<span class="lineNum">     117 </span>            :   }
<span class="lineNum">     118 </span>            : 
<span class="lineNum">     119 </span>            :   void writeConnectFlags(MqttByteBuffer stream) {
<span class="lineNum">     120 </span><span class="lineCov">          8 :     connectFlags.writeTo(stream);</span>
<span class="lineNum">     121 </span>            :   }
<span class="lineNum">     122 </span>            : 
<span class="lineNum">     123 </span>            :   /// Read functions
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span>            :   void readProtocolName(MqttByteBuffer stream) {
<span class="lineNum">     126 </span><span class="lineCov">          8 :     protocolName = MqttByteBuffer.readMqttString(stream);</span>
<span class="lineNum">     127 </span><span class="lineCov">         20 :     length += protocolName.length + 2; // 2 for length short at front of string</span>
<span class="lineNum">     128 </span>            :   }
<span class="lineNum">     129 </span>            : 
<span class="lineNum">     130 </span>            :   void readProtocolVersion(MqttByteBuffer stream) {
<span class="lineNum">     131 </span><span class="lineCov">          8 :     protocolVersion = stream.readByte();</span>
<span class="lineNum">     132 </span><span class="lineCov">          8 :     length++;</span>
<span class="lineNum">     133 </span>            :   }
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span>            :   void readKeepAlive(MqttByteBuffer stream) {
<span class="lineNum">     136 </span><span class="lineCov">          8 :     keepAlive = stream.readShort();</span>
<span class="lineNum">     137 </span><span class="lineCov">          8 :     length += 2;</span>
<span class="lineNum">     138 </span>            :   }
<span class="lineNum">     139 </span>            : 
<span class="lineNum">     140 </span>            :   void readReturnCode(MqttByteBuffer stream) {
<span class="lineNum">     141 </span><span class="lineCov">         12 :     returnCode = MqttConnectReturnCode.values[stream.readByte()];</span>
<span class="lineNum">     142 </span><span class="lineCov">          8 :     length++;</span>
<span class="lineNum">     143 </span>            :   }
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span>            :   void readTopicName(MqttByteBuffer stream) {
<span class="lineNum">     146 </span><span class="lineCov">          4 :     topicName = MqttByteBuffer.readMqttString(stream);</span>
<span class="lineNum">     147 </span><span class="lineCov">         10 :     length += topicName.length + 2; // 2 for length short at front of string.</span>
<span class="lineNum">     148 </span>            :   }
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            :   void readMessageIdentifier(MqttByteBuffer stream) {
<span class="lineNum">     151 </span><span class="lineCov">          4 :     messageIdentifier = stream.readShort();</span>
<span class="lineNum">     152 </span><span class="lineCov">          4 :     length += 2;</span>
<span class="lineNum">     153 </span>            :   }
<span class="lineNum">     154 </span>            : 
<span class="lineNum">     155 </span>            :   void readConnectFlags(MqttByteBuffer stream) {
<span class="lineNum">     156 </span><span class="lineCov">          8 :     connectFlags = new MqttConnectFlags.fromByteBuffer(stream);</span>
<span class="lineNum">     157 </span><span class="lineCov">          8 :     length += 1;</span>
<span class="lineNum">     158 </span>            :   }
<span class="lineNum">     159 </span>            : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.10</a></td></tr>
  </table>
  <br>

</body>
</html>
